package cn.explink.dop.controller.app;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.explink.dop.entity.vo.DeliveryManVO;
import cn.explink.dop.entity.vo.OrderStatusRecordVO;
import cn.explink.dop.entity.vo.OrderVO;
import cn.explink.dop.enums.OrderStatusEnum;
import cn.explink.dop.service.DeliveryManService;
import cn.explink.dop.service.OrderService;
import cn.explink.dop.service.OrderStatusRecordService;
import cn.explink.eap.core.util.StringUtil;

/**
 *
 * @author songkaojun 2015年3月19日
 */
@Controller
@RequestMapping("/orderController4App")
public class OrderController4App {

	private static final int ACCEPT = 1;
	private static final int REFUSE = 2;
	private static final int PICK = 3;
	private static final int SUCCESS = 4;
	private static final int FAIL = 5;

	@Autowired
	private OrderService orderService;

	@Autowired
	private DeliveryManService deliveryManService;
	@Autowired
	private OrderStatusRecordService orderStatusRecordService;

	/**
	 *
	 * @Title: getToDistributeOrderCount
	 * @Description: 获取各个状态订单数量
	 * @author 孟凡岭
	 * @param @param userId
	 * @param @param request
	 * @param @return
	 * @return Integer 返回类型
	 * @throws
	 */
	@RequestMapping(params = "getToDistributeOrderCount")
	@ResponseBody
	public Integer getToDistributeOrderCount(String userId, HttpServletRequest request) {
		if ((null == userId)) {
			return Integer.valueOf(0);
		}
		try {
			DeliveryManVO deliveryManVO = this.deliveryManService.queryByUserId(userId);
			if (deliveryManVO == null) {
				return Integer.valueOf(0);
			}
			List<Integer> statusList = new ArrayList<Integer>();
			statusList.add(OrderStatusEnum.ASSIGNED.getValue());
			statusList.add(OrderStatusEnum.TO_DISTRIBUTE.getValue());
			statusList.add(OrderStatusEnum.RECEIVE_ORDER.getValue());
			statusList.add(OrderStatusEnum.READY_DILIVERY.getValue());
			int count = this.orderService.getCountByStatus(deliveryManVO.getId(), statusList);

			return count;
		} catch (Exception e) {
			e.printStackTrace();
			return Integer.valueOf(0);
		}
	}

	@RequestMapping(params = "getHistoryOrderCountByStatus")
	@ResponseBody
	public Integer getHistoryOrderCountByStatus(String userId, HttpServletRequest request) {
		if ((null == userId)) {
			return Integer.valueOf(0);
		}
		try {
			DeliveryManVO deliveryManVO = this.deliveryManService.queryByUserId(userId);
			if (deliveryManVO == null) {
				return Integer.valueOf(0);
			}
			List<Integer> statusList = new ArrayList<Integer>();
			statusList.add(OrderStatusEnum.SIGN_RECEIVE.getValue());
			statusList.add(OrderStatusEnum.REFUSE_RECEIVE.getValue());
			int count = this.orderService.getCountByStatus(deliveryManVO.getId(), statusList);

			return count;
		} catch (Exception e) {
			e.printStackTrace();
			return Integer.valueOf(0);
		}
	}

	/**
	 *
	 * @param status
	 * @param request
	 * @return 获取各个状态订单列表
	 */
	@RequestMapping(params = "getToDistributeSummaryOrderListByStatus")
	@ResponseBody
	public List<OrderVO> getToDistributeSummaryOrderListByStatus(String userId, @RequestParam(value = "pageNum", required = false, defaultValue = "1") int pageNum,
			@RequestParam(value = "pageSize", required = false, defaultValue = "10") int pageSize, HttpServletRequest request) {
		List<OrderVO> summaryOrderList = new ArrayList<OrderVO>();

		if (null == userId) {
			return summaryOrderList;
		}
		try {
			DeliveryManVO deliveryManVO = this.deliveryManService.queryByUserId(userId);
			if (deliveryManVO == null) {
				return summaryOrderList;
			}

			List<Integer> statusList = new ArrayList<Integer>();
			statusList.add(OrderStatusEnum.ASSIGNED.getValue());
			statusList.add(OrderStatusEnum.TO_DISTRIBUTE.getValue());
			statusList.add(OrderStatusEnum.RECEIVE_ORDER.getValue());
			statusList.add(OrderStatusEnum.READY_DILIVERY.getValue());
			List<OrderVO> orderVOList = this.orderService.getOrderVOListByStatusAndDate4APP(deliveryManVO.getId(), statusList, pageNum, 0, pageSize, null, null);
			for (OrderVO orderVO : orderVOList) {
				OrderVO summaryOrderVO = new OrderVO();

				summaryOrderVO.setId(orderVO.getId());
				summaryOrderVO.setCode(orderVO.getCode());
				summaryOrderVO.setOrderName(orderVO.getOrderName());
				summaryOrderVO.setCustAddress(orderVO.getCustAddress());
				summaryOrderVO.setStatus(orderVO.getStatus());
				summaryOrderVO.setTotalPrice(orderVO.getTotalPrice());

				summaryOrderList.add(summaryOrderVO);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}

		return summaryOrderList;
	}

	/**
	 *
	 * @param status
	 * @param request
	 * @return 获取历史账单明细（id，名称、地址、状态、总价）
	 */
	@RequestMapping(params = "getHistorySummaryOrderListByStatus")
	@ResponseBody
	public List<OrderVO> getHistorySummaryOrderListByStatus(String userId, @RequestParam(value = "pageNum", required = false, defaultValue = "1") int pageNum,
			@RequestParam(value = "pageNumOffset", required = false, defaultValue = "0") int pageNumOffset, @RequestParam(value = "pageSize", required = false, defaultValue = "10") int pageSize,
			HttpServletRequest request) {
		List<OrderVO> orderVOList = new ArrayList<OrderVO>();
		if (null == userId) {
			return orderVOList;
		}
		try {
			DeliveryManVO deliveryManVO = this.deliveryManService.queryByUserId(userId);
			if (deliveryManVO == null) {
				return orderVOList;
			}

			List<Integer> statusList = new ArrayList<Integer>();
			statusList.add(OrderStatusEnum.SIGN_RECEIVE.getValue());
			statusList.add(OrderStatusEnum.REFUSE_RECEIVE.getValue());
			orderVOList = this.orderService.getOrderVOListByStatusAndDate4APP(deliveryManVO.getId(), statusList, pageNum, pageNumOffset, pageSize, null, null);
		} catch (Exception e) {
			e.printStackTrace();
		}

		return orderVOList;
	}

	/**
	 *
	 * @Title: getWaitSendOrder
	 * @Description: 获取待配送的订单，按照送餐时间排序
	 * @author 孟凡岭
	 * @param @param userId
	 * @param @param request
	 * @param @return
	 * @return List<OrderVO> 返回类型
	 * @throws
	 */
	@RequestMapping(params = "getWaitSendOrder")
	@ResponseBody
	public List<OrderVO> getWaitSendOrder(String userId, @RequestParam(value = "pageNum", required = false, defaultValue = "1") int pageNum,
			@RequestParam(value = "pageNumOffset", required = false, defaultValue = "0") int pageNumOffset, @RequestParam(value = "pageSize", required = false, defaultValue = "10") int pageSize,
			HttpServletRequest request) {
		if (StringUtils.isBlank(userId)) {
			return new ArrayList<OrderVO>();
		}
		DeliveryManVO deliveryManVO = this.deliveryManService.queryByUserId(userId);
		List<Integer> statusList = new ArrayList<Integer>();
		statusList.add(OrderStatusEnum.ASSIGNED.getValue());
		statusList.add(OrderStatusEnum.TO_DISTRIBUTE.getValue());
		statusList.add(OrderStatusEnum.READY_DILIVERY.getValue());
		statusList.add(OrderStatusEnum.RECEIVE_ORDER.getValue());

		List<OrderVO> list = this.orderService.getWaitSendOrder(deliveryManVO.getId(), statusList, pageNum, pageNumOffset, pageSize);
		return list;
	}

	/**
	 *
	 * @Title: getDetailOrderListById
	 * @Description: 返回订单详细信息
	 * @author 孟凡岭
	 * @param @param orderId
	 * @param @param request
	 * @param @return
	 * @return OrderVO 返回类型
	 * @throws
	 */
	@RequestMapping(params = "getDetailOrderListById")
	@ResponseBody
	public OrderVO getDetailOrderListById(String orderId, HttpServletRequest request) {
		if ((null == orderId)) {
			return new OrderVO();
		}
		try {
			List<String> orderIdList = new ArrayList<String>();
			orderIdList.add(orderId);
			List<OrderVO> orderVOList = this.orderService.getByIdList(orderIdList);
			if ((orderVOList == null) || (orderVOList.size() == 0) || (orderVOList.size() != 1)) {
				return new OrderVO();
			}
			return orderVOList.get(0);

		} catch (Exception e) {
			e.printStackTrace();
			return new OrderVO();
		}
	}

	/**
	 *
	 * @Title: getDetailOrderListByQrcCode
	 * @Description: 通过二维码扫描后查询订单详情
	 * @author 孟凡岭
	 * @param @param userId
	 * @param @param orderId
	 * @param @param request
	 * @param @return
	 * @return Map<String, Object> 返回类型
	 * @throws
	 */
	@RequestMapping(params = "getDetailOrderListByQrcCode")
	@ResponseBody
	public Map<String, Object> getDetailOrderListByQrcCode(String userId, String orderId, HttpServletRequest request) {
		Map<String, Object> map = new HashMap<String, Object>();
		if (StringUtils.isBlank(userId) || StringUtils.isBlank(orderId)) {
			map.put("status", 1);
			return map;
		}
		/**
		 * 判断标识符
		 */
		if (orderId.contains("explink") == false) {
			map.put("status", 2);
			return map;
		}
		/**
		 * 分割数据获取订单号
		 */
		orderId = orderId.split(":")[1];
		DeliveryManVO deliveryManVO = this.deliveryManService.queryByUserId(userId.trim());
		/**
		 * 能过订单号和配送员ID查询订单
		 */
		OrderVO order = this.orderService.getByIdAndDeliveryManId(orderId, deliveryManVO.getId());
		/**
		 * null表示订单不存在或与配送员不匹配
		 */
		if (order == null) {
			map.put("status", 3);
			return map;
		}

		int status = order.getStatus();
		/**
		 * 如果状态不为3或不为2表示订单已完成
		 */
		if ((status != 3) && (status != 2)) {
			map.put("status", 4);
			return map;
		}
		/**
		 * 查询成功，返回订单
		 */
		map.put("status", 5);
		map.put("order", order);
		return map;
	}

	/**
	 *
	 * @param userId
	 * @param operateCode
	 *            接受：1 拒绝：2 已取单：3 配送成功：4 配送失败： 5
	 * @param orderIdList
	 * @param request
	 */
	@RequestMapping(params = "operateOrder")
	@ResponseBody
	public void operateOrder(String userId, Integer operateCode, String orderId, HttpServletRequest request) {
		if ((null == operateCode) || (null == userId) || (orderId == null)) {
			return;
		}
		try {
			List<String> orderIdList = new ArrayList<String>();
			List<OrderStatusRecordVO> recordList = new ArrayList<OrderStatusRecordVO>();
			orderIdList.add(orderId);

			List<OrderVO> orderVOList = this.orderService.getByIdList(orderIdList);
			DeliveryManVO deliveryManVO = this.deliveryManService.queryByUserId(userId);
			/**
			 * 获取服务器当前时间
			 */
			Date sysDate = this.orderService.getSysDate();
			SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd HH:mm");
			switch (operateCode) {
			case ACCEPT:
				for (OrderVO orderVO : orderVOList) {

					orderVO.setStatus(OrderStatusEnum.TO_DISTRIBUTE.getValue());
					orderVO.setStatusChangeTime(new Date());
					orderVO.setStatusLog(orderVO.getStatusLog() + "配送员：" + deliveryManVO.getDelName() + " 接单，时间:" + sd.format(sysDate) + " 状态：" + OrderStatusEnum.TO_DISTRIBUTE.getText());
					// TODO 批量更新
					orderVO.setStatusChangeTime(sysDate);
					orderVO.setAcceptTime(sysDate);
					orderVO.setReadyStatus(1);
					this.orderService.saveOrUpdate(orderVO);
					OrderStatusRecordVO record = new OrderStatusRecordVO();
					record.setChangTime(sysDate);
					record.setOrderId(orderId);
					record.setRecordDesc("配送员： " + deliveryManVO.getDelName() + "  已接单");
					recordList.add(record);
				}
				break;
			case REFUSE:
				for (OrderVO orderVO : orderVOList) {
					orderVO.setStatus(OrderStatusEnum.NOT_ASSIGN.getValue());
					orderVO.setStatusChangeTime(new Date());
					orderVO.setStatusLog(orderVO.getStatusLog() + "配送员：" + deliveryManVO.getDelName() + " 拒绝接单，时间:" + sd.format(sysDate) + " 状态：" + OrderStatusEnum.NOT_ASSIGN.getText());
					// 清空订单配送员之间的关系
					orderVO.setDeliveryMan(null);
					// 更新本单被拒绝的配件员ID列表
					if (StringUtil.isEmpty(orderVO.getRefuseDeliveryman())) {
						orderVO.setRefuseDeliveryman(deliveryManVO.getId());
					} else {
						orderVO.setRefuseDeliveryman(orderVO.getRefuseDeliveryman() + "," + deliveryManVO.getId());
					}
					orderVO.setStatusChangeTime(sysDate);
					orderVO.setReadyStatus(0);
					this.orderService.saveOrUpdate(orderVO);
					OrderStatusRecordVO record = new OrderStatusRecordVO();
					record.setChangTime(sysDate);
					record.setOrderId(orderId);
					record.setRecordDesc("配送员： " + deliveryManVO.getDelName() + "  拒绝接单");
					recordList.add(record);

				}
				break;
			case PICK:
				for (OrderVO orderVO : orderVOList) {
					orderVO.setStatus(OrderStatusEnum.RECEIVE_ORDER.getValue());
					orderVO.setStatusChangeTime(new Date());
					orderVO.setStatusLog(orderVO.getStatusLog() + "配送员：" + deliveryManVO.getDelName() + " 取单，时间:" + sd.format(sysDate) + " 状态：" + OrderStatusEnum.RECEIVE_ORDER.getText());
					orderVO.setStatusChangeTime(sysDate);
					orderVO.setTakeMealTime(sysDate);
					orderVO.setReadyStatus(2);
					this.orderService.saveOrUpdate(orderVO);
					OrderStatusRecordVO record = new OrderStatusRecordVO();
					record.setChangTime(sysDate);
					record.setOrderId(orderId);
					record.setRecordDesc("配送员： " + deliveryManVO.getDelName() + "  取单");
					recordList.add(record);
				}
				break;
			case SUCCESS:
				for (OrderVO orderVO : orderVOList) {
					orderVO.setStatus(OrderStatusEnum.SIGN_RECEIVE.getValue());
					orderVO.setStatusChangeTime(new Date());
					orderVO.setStatusLog(orderVO.getStatusLog() + "配送员：" + deliveryManVO.getDelName() + " 配送成功，客户已签收，时间:" + sd.format(sysDate) + " 状态：" + OrderStatusEnum.SIGN_RECEIVE.getText());
					orderVO.setStatusChangeTime(sysDate);
					orderVO.setCompleteTime(sysDate);
					this.orderService.saveOrUpdate(orderVO);
					OrderStatusRecordVO record = new OrderStatusRecordVO();
					record.setChangTime(sysDate);
					record.setOrderId(orderId);
					record.setRecordDesc("配送员： " + deliveryManVO.getDelName() + "  配送成功，客户已签收");
					recordList.add(record);
				}
				break;
			case FAIL:
				for (OrderVO orderVO : orderVOList) {
					orderVO.setStatus(OrderStatusEnum.REFUSE_RECEIVE.getValue());
					orderVO.setStatusChangeTime(new Date());
					orderVO.setStatusLog(orderVO.getStatusLog() + "配送员：" + deliveryManVO.getDelName() + " 配送未完成，原因：客户拒收，时间:" + sd.format(sysDate) + " 状态：" + OrderStatusEnum.REFUSE_RECEIVE.getText());
					orderVO.setStatusChangeTime(sysDate);
					this.orderService.saveOrUpdate(orderVO);
					OrderStatusRecordVO record = new OrderStatusRecordVO();
					record.setChangTime(sysDate);
					record.setOrderId(orderId);
					record.setRecordDesc("配送员： " + deliveryManVO.getDelName() + "  配送未完成，原因：客户拒收");
					recordList.add(record);
				}
				break;
			default:
				// 错误操作码
				break;
			}
			/**
			 * 批量保存记录
			 */
			this.orderStatusRecordService.batchSave(recordList);
		} catch (Exception e) {
			e.printStackTrace();
		}

	}

	/**
	 *
	 * @Title: getTheDayBillAccount
	 * @Description: 获取当天账单总金额
	 * @author 孟凡岭
	 * @param @param userId
	 * @param @param request
	 * @param @return
	 * @return BigDecimal 返回类型
	 * @throws
	 */
	@RequestMapping(params = "getTheDayBillAccount")
	@ResponseBody
	public BigDecimal getTheDayBillAccount(String userId, HttpServletRequest request) {
		if ((null == userId)) {
			return new BigDecimal(0);
		}
		try {
			DeliveryManVO deliveryManVO = this.deliveryManService.queryByUserId(userId);
			if (deliveryManVO == null) {
				return new BigDecimal(0);
			}

			List<Integer> statusList = new ArrayList<Integer>();
			statusList.add(OrderStatusEnum.SIGN_RECEIVE.getValue());
			List<OrderVO> orderVOList = this.orderService.getOrderVOListByStatusAndDate4APP(deliveryManVO.getId(), statusList, 0, 0, 0, this.getStartTimeOfTheDay(), this.getEndTimeOfTheDay());

			BigDecimal account = new BigDecimal(0);
			for (OrderVO orderVO : orderVOList) {
				BigDecimal totalPrice = orderVO.getTotalPrice();
				account = account.add(totalPrice);
			}
			return account;
		} catch (Exception e) {
			e.printStackTrace();
			return new BigDecimal(0);
		}
	}

	/**
	 *
	 * @Title: getTheDayBillDetail
	 * @Description: 获取当天账单明细
	 * @author 孟凡岭
	 * @param @param userId
	 * @param @param request
	 * @param @return
	 * @return List<OrderVO> 返回类型
	 * @throws
	 */
	@RequestMapping(params = "getTheDayBillDetail")
	@ResponseBody
	public List<OrderVO> getTheDayBillDetail(String userId, @RequestParam(value = "pageNum", required = false, defaultValue = "1") int pageNum,
			@RequestParam(value = "pageSize", required = false, defaultValue = "10") int pageSize, HttpServletRequest request) {
		if ((null == userId)) {
			return new ArrayList<OrderVO>();
		}
		try {
			DeliveryManVO deliveryManVO = this.deliveryManService.queryByUserId(userId);
			if (deliveryManVO == null) {
				return new ArrayList<OrderVO>();
			}

			List<Integer> statusList = new ArrayList<Integer>();
			statusList.add(OrderStatusEnum.SIGN_RECEIVE.getValue());
			List<OrderVO> orderVOList = this.orderService.getOrderVOListByStatusAndDate4APP(deliveryManVO.getId(), statusList, pageNum, 0, pageSize, this.getStartTimeOfTheDay(),
					this.getEndTimeOfTheDay());
			return orderVOList;
		} catch (Exception e) {
			e.printStackTrace();
			return new ArrayList<OrderVO>();
		}
	}

	/**
	 *
	 * @Title: getHistoryBillAccount
	 * @Description: 获取历史账单总金额
	 * @author 孟凡岭
	 * @param @param userId
	 * @param @param request
	 * @param @return
	 * @return BigDecimal 返回类型
	 * @throws
	 */
	@RequestMapping(params = "getHistoryBillAccount")
	@ResponseBody
	public BigDecimal getHistoryBillAccount(String userId, HttpServletRequest request) {
		if ((null == userId)) {
			return new BigDecimal(0);
		}
		try {
			DeliveryManVO deliveryManVO = this.deliveryManService.queryByUserId(userId);
			if (deliveryManVO == null) {
				return new BigDecimal(0);
			}

			List<Integer> statusList = new ArrayList<Integer>();
			statusList.add(OrderStatusEnum.SIGN_RECEIVE.getValue());
			List<OrderVO> orderVOList = this.orderService.getOrderVOListByStatusAndDate4APP(deliveryManVO.getId(), statusList, 0, 0, 0,
					new SimpleDateFormat("yyyy-MM-dd HH:mm").parse("1900-01-01 00:00"), this.getStartTimeOfTheDay());

			BigDecimal account = new BigDecimal(0);
			for (OrderVO orderVO : orderVOList) {
				BigDecimal totalPrice = orderVO.getTotalPrice();
				account = account.add(totalPrice);
			}
			return account;

		} catch (Exception e) {
			e.printStackTrace();
			return new BigDecimal(0);
		}
	}

	/**
	 *
	 * @Title: getHistoryBillDetail
	 * @Description: 获取历史账单明细
	 * @author 孟凡岭
	 * @param @param userId
	 * @param @param request
	 * @param @return
	 * @return List<OrderVO> 返回类型
	 * @throws
	 */
	@RequestMapping(params = "getHistoryBillDetail")
	@ResponseBody
	public List<OrderVO> getHistoryBillDetail(String userId, @RequestParam(value = "pageNum", required = false, defaultValue = "1") int pageNum,
			@RequestParam(value = "pageSize", required = false, defaultValue = "10") int pageSize, HttpServletRequest request) {
		if ((null == userId)) {
			return new ArrayList<OrderVO>();
		}
		try {
			DeliveryManVO deliveryManVO = this.deliveryManService.queryByUserId(userId);
			if (deliveryManVO == null) {
				return new ArrayList<OrderVO>();
			}

			List<Integer> statusList = new ArrayList<Integer>();
			statusList.add(OrderStatusEnum.SIGN_RECEIVE.getValue());
			List<OrderVO> orderVOList = this.orderService.getOrderVOListByStatusAndDate4APP(deliveryManVO.getId(), statusList, pageNum, 0, pageSize,
					new SimpleDateFormat("yyyy-MM-dd HH:mm").parse("1900-01-01 00:00"), this.getStartTimeOfTheDay());
			return orderVOList;

		} catch (Exception e) {
			e.printStackTrace();
			return new ArrayList<OrderVO>();
		}
	}

	/**
	 *
	 * @Title: getTheDayUpMoney
	 * @Description:当天需要缴纳多少钱和已缴纳多少钱 ：需要缴纳--->当天实收款总减当天取餐付款总数 ：已缴纳--->状态为已成功的
	 * @author 孟凡岭
	 * @param @param userId
	 * @param @param request
	 * @param @return
	 * @return BigDecimal 返回类型
	 * @throws
	 */
	@RequestMapping(params = "getTheDayUpMoney")
	@ResponseBody
	public Map<String, Object> getTheDayUpMoney(String userId, HttpServletRequest request) {
		if (StringUtils.isBlank(userId)) {
			return null;
		}
		DeliveryManVO deliveryManVO = this.deliveryManService.queryByUserId(userId.trim());
		return this.orderService.getTheDayUpMoney(deliveryManVO.getId());
	}

	/**
	 *
	 * @Title: getUpMoneyAndOrderList
	 * @Description: 获取当天需要缴纳订单列表，支付方式为现金
	 * @author 孟凡岭
	 * @param @param userId
	 * @param @param request
	 * @param @return
	 * @return Map<String,Object> 返回类型
	 * @throws
	 */
	@RequestMapping(params = "getUpMoneyAndOrderList")
	@ResponseBody
	public Map<String, Object> getUpMoneyAndOrderList(String userId, @RequestParam(value = "pageNum", required = false, defaultValue = "1") int pageNum,
			@RequestParam(value = "pageSize", required = false, defaultValue = "10") int pageSize, HttpServletRequest request) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("orderList", new ArrayList<OrderVO>());
		if (StringUtils.isBlank(userId)) {
			return map;
		}
		DeliveryManVO deliveryManVO = this.deliveryManService.queryByUserId(userId.trim());
		/**
		 * 获取已完成的订单列表
		 */
		List<OrderVO> orderList = this.orderService.getDaySuccessOrderList(deliveryManVO.getId(), pageNum, pageSize);
		map.put("orderList", orderList);
		return map;
	}

	/**
	 *
	 * @Title: getAlreadyMoneyAndOrderList
	 * @Description: 获取已经缴纳金钱的订单列表
	 * @author 孟凡岭
	 * @param @param userId
	 * @param @param pageNum
	 * @param @param pageSize
	 * @param @param request
	 * @param @return
	 * @return Map<String,Object> 返回类型
	 * @throws
	 */
	@RequestMapping(params = "getAlreadyMoneyAndOrderList")
	@ResponseBody
	public List<Map<String, Object>> getAlreadyMoneyAndOrderList(String userId, @RequestParam(value = "pageNum", required = false, defaultValue = "1") int pageNum,
			@RequestParam(value = "pageSize", required = false, defaultValue = "10") int pageSize, HttpServletRequest request) {
		if (StringUtils.isBlank(userId)) {
			return new ArrayList<Map<String, Object>>();
		}
		DeliveryManVO deliveryManVO = this.deliveryManService.queryByUserId(userId.trim());
		List<Map<String, Object>> list = this.orderService.getAlreadyMoneyAndOrderList(deliveryManVO.getId(), pageNum, pageSize);
		return list;
	}

	/**
	 *
	 * @Title: getTheDaySuccessOrderDetail
	 * @Description: 获取当天帐单详情
	 * @author 孟凡岭
	 * @param
	 * @return void 返回类型
	 * @throws
	 */
	@RequestMapping(params = "getTheDaySuccessOrderDetail")
	@ResponseBody
	public List<Map<String, Object>> getTheDaySuccessOrderDetail(String userId, @RequestParam(value = "pageNum", required = false, defaultValue = "1") int pageNum,
			@RequestParam(value = "pageSize", required = false, defaultValue = "10") int pageSize, HttpServletRequest request) {
		if (StringUtils.isBlank(userId)) {
			return new ArrayList<Map<String, Object>>();
		}
		DeliveryManVO deliveryManVO = this.deliveryManService.queryByUserId(userId.trim());
		List<Map<String, Object>> list = this.orderService.getTheDaySuccessOrderDetail(deliveryManVO.getId(), pageNum, pageSize);

		return list;
	}

	/**
	 *
	 * @Title: getRealityIncome
	 * @Description: 获取当天实际收入
	 * @author 孟凡岭
	 * @param @param userId
	 * @param @param request
	 * @param @return
	 * @return BigDecimal 返回类型
	 * @throws
	 */
	@RequestMapping(params = "getRealityIncome")
	@ResponseBody
	public BigDecimal getRealityIncome(String userId, HttpServletRequest request) {
		BigDecimal dec = new BigDecimal(0);
		if (StringUtils.isBlank(userId)) {
			return dec;
		}
		DeliveryManVO deliveryManVO = this.deliveryManService.queryByUserId(userId.trim());
		dec = this.orderService.getRealityIncome(deliveryManVO.getId());
		return dec;
	}

	/**
	 *
	 * @Title: getMonthIncome
	 * @Description: 获取当月实际收入
	 * @author 孟凡岭
	 * @param @param userId
	 * @param @param request
	 * @param @return
	 * @return BigDecimal 返回类型
	 * @throws
	 */
	@RequestMapping(params = "getMonthIncome")
	@ResponseBody
	public BigDecimal getMonthIncome(String userId, HttpServletRequest request) {
		BigDecimal dec = new BigDecimal(0);
		if (StringUtils.isBlank(userId)) {
			return dec;
		}
		dec = this.orderService.getMonthIncome(userId);
		return dec;
	}

	/**
	 *
	 * @Title: getOrderQrcCode
	 * @Description: 获取订单二维码
	 * @author 孟凡岭
	 * @param @return
	 * @return String 返回类型
	 * @throws
	 */
	@RequestMapping(params = "getOrderQrcCode")
	@ResponseBody
	public String getOrderQrcCode() {
		return "explink:402880534d4ae0d6014d4aec844f0002";
	}

	private Date getStartTimeOfTheDay() {
		Calendar currentDate = new GregorianCalendar();

		currentDate.set(Calendar.HOUR_OF_DAY, 0);
		currentDate.set(Calendar.MINUTE, 0);
		currentDate.set(Calendar.SECOND, 0);
		return (Date) currentDate.getTime().clone();
	}

	private Date getEndTimeOfTheDay() {
		Calendar currentDate = new GregorianCalendar();

		currentDate.set(Calendar.HOUR_OF_DAY, 23);
		currentDate.set(Calendar.MINUTE, 59);
		currentDate.set(Calendar.SECOND, 59);
		return (Date) currentDate.getTime().clone();
	}
}
